
/***  DOCUMENTATION LAYER

	Generic Jini (Javascript Initialization) File

	Last Update: Apr 2007
	Author: Tom at klenwell@gmail.com
	License: GPL License (http://www.opensource.org/licenses/gpl-license.php)

NOTES
	The idea is that you'd call this once and it would define this class's meta data,
	auto-load all the other files it requires, and declare the base class of your package.
	
	** Be sure to rename your base class **

	To link: <script type="text/javascript" src="path/to/file.js"></script>

REFERENCE
	http://developer.mozilla.org/en/docs/JavaScript

______________________________________________________________________________*/


// package meta information
// ** EDIT THIS SECTION
/*____________________________________________________________________________*/

var META = new Object();
META['name'] = 'Kwyption';
META['version'] = '0.6';
META['last_update'] = 'Apr 2007';
META['license'] = 'GPL 2';
META['dirpath'] = '%TBD%';
META['filename'] = 'kwyption.ini.js';

// Dependant Files to Be Autoloaded (all must branch off same dirpath)
META['INCLUDE'] = [ 'kwyption.core.js', 'md5.js', 'rc4.js' ];

/*____________________________________________________________________________*/


// autoload dependant files
// ** DO NOT EDIT THIS SECTION
/*____________________________________________________________________________*/

// autoload function (this is what script.aculo.us currently uses)
function _autoload(url) { document.write('<script type="text/javascript" src="'+url+'"></script>'); }

// dynamically determine this file's directory path (META['dirpath'])
if ( META['INCLUDE'].length > 0 )
{
	// set fname regex and initialize other vars
	var _regex_fname = new RegExp(META['filename'], 'i');
	var _regex_http = new RegExp('^http', 'i');
	var _script_src = '%empty%';
		
	// create scriptlist object
	var ScriptList = document.getElementsByTagName('script');
	
	// cycle scriptlist looking for this files src value
	for ( var i=0; i < ScriptList.length; i++ )
	{
		var _src = ScriptList[i].getAttribute('src');
		if ( _src != null && _src.search(_regex_fname) != -1 )
		{
			var ScriptSrcNode = ScriptList[i];
			_script_src = _src;
			break;
		}
	}
	
	// did we find the src we were looking for?
	if ( _script_src == '%empty%' )
	{
		alert("unable to find script source - please check init file META['filename'] setting");
		_fx_fatal_error(); 
	}
	
	// get url dirname from source
	var _ss_lio = _script_src.lastIndexOf ( '/' ); 
	META['dirpath'] = _ss_lio >= 0 ? _script_src.substring( 0, _ss_lio + 1 ) : '';
	
	// Load files
	for ( var i=0; i < META['INCLUDE'].length; i++ )
	{
		_inc = META['INCLUDE'][i];
		_new_src = ( _inc.search(_regex_http) != -1 ) ? _inc : META['dirpath'] + _inc;
		_autoload(_new_src);	/* see fx above */
		if ( 0 ) alert(_new_src);	/* debug */
	}
}

/*____________________________________________________________________________*/


// base class constructor
// ** EDIT Class Name
/*____________________________________________________________________________*/
function Kwyption(_debug)
{
	// set meta properties
	this.debug = _debug;
	this.name = META['name'];
	this.version = META['version'];
	this.filename = META['filename'];
	this.dirpath = META['dirpath'];
	this.INCLUDE = META['INCLUDE'];

	/* extend this class with an ini method and call that to pass any needed parameters */

}; // end cx
/*____________________________________________________________________________*/

